import { FSMSystem } from './FSMSystem';
import { FSMState } from './State';
import IFSMEvent from './IFSMEvent';

const { ccclass, property } = cc._decorator;

//cc.Enum(FSMState)
@ccclass
export class FSMControl extends cc.Component implements IFSMEvent {
    // @property({
    //     type: FSMState
    // })
    public defaultState: FSMState = FSMState.Idle;

    @property(cc.Label)
    label: cc.Label = null

    public fsmAction: FSMSystem = null;

    onLoad() {
        this.fsmAction = new FSMSystem(this);
    }

    start() {
        this.fsmAction.start(this.defaultState);
    }

    update(dt: number) {
        this.fsmAction.update();
    }

    /**
     * 当进入一个状态时被调用
     * @param state 进入的状态
     */
    public onStateEnter(state: string) {
        this.label.string = state;
        //cc.log('onStateEnter:' + state.toString())
    }

    /**
     * 处于一个状态中每帧调用
     * @param state 当前状态
     */
    public onStateStay(state: string) {
        this.label.string = state;
        //cc.log('onStateStay:' + state.toString())
    }

    /**
     * 当离开一个状态时被调用
     * @param state 离开的状态
     */
    public onStateExit(state: string) {
        //cc.log('onStateExit:' + state.toString())
    }
}
